<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8">
		<title>修改页面</title>
		<link rel="stylesheet" href="../../../component/pear/css/pear.css" />
	</head>
	<body>
		<form class="layui-form" action="">
			<div class="mainBox">
				<div class="main-container">
				<div class="layui-form-item">
						<label class="layui-form-label">电影编号</label>
						<div class="layui-input-block">
							<input type="text" id="mid" name="mid" readonly lay-verify="title" autocomplete="off" 
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">电影名称</label>
						<div class="layui-input-block">
							<input type="text" id="mname" name="mname" lay-verify="title" autocomplete="off" placeholder="请输入电影名称"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">导演</label>
						<div class="layui-input-block">
							<input type="text" id="mdirector"  name="mdirector" value="测试导演" lay-verify="title" autocomplete="off" placeholder="请输入导演"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">主演</label>
						<div class="layui-input-block">
							<input type="text"  id="mactor" name="mactor" value="测试演员" lay-verify="title" autocomplete="off" placeholder="请输入演员"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">类型</label>
						<div class="layui-input-block">
							<input type="text" id="mtype" name="mtype" value="测试类型" lay-verify="title" autocomplete="off" placeholder="请输入类型"
								class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">上映日期</label>
						<div class="layui-input-block">
							<input type="date" id="mdate" name="mdate"  lay-verify="title" autocomplete="off" 
								class="layui-input">
						</div>
					</div>
					
					<div class="layui-form-item">
						<label class="layui-form-label">评分</label>
						<div class="layui-input-block">
							<input type="text" id="mscore" name="mscore"  lay-verify="title" autocomplete="off" 
								class="layui-input" placeholder="请输入评分">
						</div>
					</div>
					
				
					<div class="layui-form-item">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block">
							<textarea  id="msummary" name="msummary"  lay-verify="title" autocomplete="off" 
								class="layui-input"></textarea>
						</div>
					</div>
					
				</div>
			</div>
			<div class="bottom">
				<div class="button-container">
					<button type="submit" class="pear-btn pear-btn-primary pear-btn-sm" lay-submit=""
						lay-filter="movie-save">
						<i class="layui-icon layui-icon-ok"></i>
						提交
					</button>
					<button type="reset" class="pear-btn pear-btn-sm">
						<i class="layui-icon layui-icon-refresh"></i>
						重置
					</button>
				</div>
			</div>
		</form>
		<script src="../../../component/layui/layui.js"></script>
		<script src="../../../component/pear/pear.js"></script>
		<script>
			layui.use(['form', 'jquery'], function() {
				let form = layui.form;
				let $ = layui.jquery;
				
				//从localStorage中读取对象，并将属性的值显示在表单中
				var obj = localStorage.getItem("obj");	
				//需要转换
				obj = JSON.parse(obj);
				console.log(obj.data['mname'])
				//给表单元素赋值
				$("#mid").val(obj.data['mid'])
				$("#mname").val(obj.data['mname'])
				$("#mdirector").val(obj.data['mdirector'])
				$("#mtype").val(obj.data['mtype'])
				$("#mdate").val(obj.data['mdate'])
				$("#mscore").val(obj.data['mscore'])
				$("#mactor").val(obj.data['mactor'])
				$("#msummary").val(obj.data['msummary'])
			
				//修改保存
				form.on('submit(movie-save)', function(data) {
					$.ajax({
						url: '/0625jdbcdemo/MovieServlet?op=update',
						data: JSON.stringify(data.field),
						dataType: 'json',
						contentType: 'application/json',
						type: 'post',
						success: function(result) {
							if (result.msg=="success") {
								layer.msg("修改成功!", {
									icon: 1,
									time: 1000
								}, function() {
									parent.layer.close(parent.layer.getFrameIndex(window
										.name)); //关闭当前页
									parent.layui.table.reload("movie-table");
								});
							} else {
								layer.msg("修改失败!", {
									icon: 2,
									time: 1000
								});
							}
						}
					})
					return false;
				});
			})
		</script>
		<script>
		</script>
	</body>
</html>
